package com.cloud.base.aspect;

import com.cloud.base.utils.BuildReturnDataUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * @author liuyuan
 * */
@Component
@Aspect
public class SetFiledValueAspect {

    @Autowired
    BuildReturnDataUtils buildReturnDataUtils;


    @Around("@annotation(com.cloud.base.annotation.LinkedQuery)")
    public Object doSetFiledValue(ProceedingJoinPoint joinPoint) throws Throwable {
        Object proceed = joinPoint.proceed();
        if(proceed instanceof Collection){
            buildReturnDataUtils.setBeansFiled((Collection)proceed);
        }else {
            buildReturnDataUtils.setBeanFiled(proceed);
        }
        return proceed;
    }
}
